package com.example.yunifang;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.TextView;

import com.astuetz.PagerSlidingTabStrip;
import com.example.yunifang.bean.FeiLeiBean.Data.Category;
import com.example.yunifang.fragment.FenLeiFragment;
import com.example.yunifang.fragment.Fragment2;

public class FenLeiActivity extends FragmentActivity {

	public static Category name;
	private TextView fenlei_title;
	public static RadioButton fenlei_back_radio;
	public static int i=0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_fen_lei);
		name = (Category) getIntent().getSerializableExtra("category");
		inti();
	}

	public void inti() {
		PagerSlidingTabStrip tabs=(PagerSlidingTabStrip) findViewById(R.id.tabs);
		ViewPager vp=(ViewPager)findViewById(R.id.fenlei_my_vp);
		int fragment_id=getIntent().getIntExtra("fragment_id", 0);
		
		vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
			
			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return name.children.size();
			}
			
			@Override
			public Fragment getItem(int arg0) {
				// TODO Auto-generated method stub
				Fragment fragment=new FenLeiFragment();
				Bundle args = new Bundle();
				args.putInt("pos", arg0);
				fragment.setArguments(args);
				return fragment;
			}
			@Override
			public CharSequence getPageTitle(int position) {
				// TODO Auto-generated method stub
				return name.children.get(position).cat_name;
			}
			
			
		});
		tabs.setViewPager(vp);
		vp.setCurrentItem(fragment_id);
		fenlei_title=(TextView)findViewById(R.id.fenlei_title);
		fenlei_title.setText(name.cat_name);
		fenlei_back_radio=(RadioButton)findViewById(R.id.fenlei_back_radio);
		fenlei_back_radio.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				i=1;
				Intent intent=new Intent(FenLeiActivity.this,ZhuActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.infragment, R.anim.outfragment);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.fen_lei, menu);
		return true;
	}

}
